package com.cow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cow.dao.ProductMapper;
import com.cow.entity.Product;
import com.cow.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

    @Autowired
    private ProductMapper productMapper;
    @Override
    public List<Product> findAllWithConditions(String by, String keyWord) {
        QueryWrapper<Product> wrapper = new QueryWrapper<>();
        if (keyWord !=null && !keyWord.isEmpty()){
            switch (by){
                case "name":
                    wrapper.like("product_name",keyWord);
                    break;
                case "type":
                    wrapper.like("product_type",keyWord);
                    break;
                case "brand":
                    wrapper.like("product_brand",keyWord);
                    break;
            }
        }
        wrapper.eq("is_sale",1);

        return this.list(wrapper);
    }

    @Override
    public Map<String, Object> productOverView() {
        return productMapper.productOverView();
    }
}
